#include <stdio.h>
#include <atlbase.h>

#include "USB.h"
#include "USBHub.h"
#include "USBPort.h"
#include "USBDevice.h"

int main()
{
	USES_CONVERSION;

	USB usb;
	const std::vector<USBController*> *pHostList = usb.GetHostControllers();

	for (std::vector<USBController*>::const_iterator	iter = pHostList->begin();
														iter != pHostList->end();
														++iter)
	{
		USBController *pController = *iter;
		USBHub *pHub = pController->GetRootHub();
		const std::vector<USBPort*> *pPorts = pHub->GetPorts();
		
		for (std::vector<USBPort*>::const_iterator	iter = pPorts->begin();
													iter != pPorts->end();
													++iter)
		{
			USBPort *pUSBPort = *iter;
			if (pUSBPort->IsDeviceConnected() && !pUSBPort->IsHub())
			{
				USBDevice *pDevice = pUSBPort->GetDevice();
				printf("Serial Number: %s\n", W2A(pDevice->GetSerialNumber().c_str()));
				printf("Device Name: %s\n", W2A(pDevice->GetName().c_str()));

				std::wstring usbSpeed;
				switch (pUSBPort->GetSpeed())
				{
				case UsbLowSpeed:
					usbSpeed = L"USB 1.0";
					break;
				case UsbFullSpeed:
					usbSpeed = L"USB 1.1";
					break;
				case UsbHighSpeed:
					usbSpeed = L"USB 2.0";
					break;
				case USBSuperSpeed:
					usbSpeed = L"USB 3.0";
					break;
				case USBSuperSpeedPlus:
					usbSpeed = L"USB 3.1";
					break;
				default:
					usbSpeed = L"Unknown";
					break;
				}

				printf("Speed: %s\n", W2A(usbSpeed.c_str()));
				printf("Port: %d\n\n", pDevice->GetPortNumber());
			}
		}
	}
}